﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GamePlugin.Logics.Core;
using WindowsInput;
using GamePlugin.IO;

namespace GamePlugin.Logics.Game.Actions
{
    public class DActionAuction : MachineState
    {
        public DActionAuction()
        {
            AddState(typeof(DActionAuctionStart).Name, new DActionAuctionStart());
            this[typeof(DActionAuctionStart).Name].UpdateEvent += new EventHandler<GameTimeEventArgs>((o, e) => this.CheckKeys(o, e));

            AddState(typeof(DActionAuctionGrabData).Name, new DActionAuctionGrabData());
            this[typeof(DActionAuctionGrabData).Name].UpdateEvent += new EventHandler<GameTimeEventArgs>((o, e) => this.CheckKeys(o, e));

            AddState(typeof(DActionAuctionReceiveItems).Name, new DActionAuctionReceiveItems());
            this[typeof(DActionAuctionReceiveItems).Name].UpdateEvent += new EventHandler<GameTimeEventArgs>((o, e) => this.CheckKeys(o, e));

            AddState(typeof(DActionAuctionCollectDeadline).Name, new DActionAuctionCollectDeadline());
            this[typeof(DActionAuctionCollectDeadline).Name].UpdateEvent += new EventHandler<GameTimeEventArgs>((o, e) => this.CheckKeys(o, e));

            AddState(typeof(DActionAuctionTryAuctionItem).Name, new DActionAuctionTryAuctionItem());
            this[typeof(DActionAuctionTryAuctionItem).Name].UpdateEvent += new EventHandler<GameTimeEventArgs>((o, e) => this.CheckKeys(o, e));

            AddState(typeof(DActionAuctionEnd).Name, new DActionAuctionEnd());
            this[typeof(DActionAuctionEnd).Name].UpdateEvent += new EventHandler<GameTimeEventArgs>((o, e) => this.CheckKeys(o, e));

            this.DefaultState = typeof(DActionAuctionStart).Name;
        }


        public void CheckKeys(object o, GameTimeEventArgs e)
        {
            InputSimulator input = Helper.DiabloPluginGame.InputSimulator;

            // stop
            if (input.InputDeviceState.IsKeyDown(WindowsInput.Native.VirtualKeyCode.F4))
            {
                IOManager.Instance.CloseLogFile();
                this.Owner.ChangeToState(typeof(DActionIdle).Name);
                this.IsNeedReset = true;
                this.Owner.IsNeedReset = true;
                
                Helper.Log("End of Diablo Plugin");
            }
        }
    }
}
